package com.linx.system.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.linx.common.core.domain.R;
import com.linx.common.core.validate.AddGroup;
import com.linx.common.core.validate.EditGroup;
import com.linx.common.excel.utils.ExcelUtil;
import com.linx.common.idempotent.annotation.RepeatSubmit;
import com.linx.common.log.annotation.Log;
import com.linx.common.log.enums.BusinessType;
import com.linx.common.mybatis.core.page.PageQuery;
import com.linx.common.mybatis.core.page.TableDataInfo;
import com.linx.common.web.core.BaseController;
import com.linx.system.domain.bo.SysUserParkBo;
import com.linx.system.domain.vo.SysUserParkVo;
import com.linx.system.service.ISysUserParkService;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户园区关联
 *
 * @author linx
 * @date 2024-11-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/userPark")
public class SysUserParkController extends BaseController {

    private final ISysUserParkService sysUserParkService;

    /**
     * 查询用户园区关联列表
     */
    @SaCheckPermission("system:userPark:list")
    @GetMapping("/list")
    public TableDataInfo<SysUserParkVo> list(SysUserParkBo bo, PageQuery pageQuery) {
        return sysUserParkService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出用户园区关联列表
     */
    @SaCheckPermission("system:userPark:export")
    @Log(title = "用户园区关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysUserParkBo bo, HttpServletResponse response) {
        List<SysUserParkVo> list = sysUserParkService.queryList(bo);
        ExcelUtil.exportExcel(list, "用户园区关联", SysUserParkVo.class, response);
    }

    /**
     * 获取用户园区关联详细信息
     *
     * @param userParkId 主键
     */
    @SaCheckPermission("system:userPark:query")
    @GetMapping("/{userParkId}")
    public R<SysUserParkVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long userParkId) {
        return R.ok(sysUserParkService.queryById(userParkId));
    }

    /**
     * 新增用户园区关联
     */
    @SaCheckPermission("system:userPark:add")
    @Log(title = "用户园区关联", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody SysUserParkBo bo) {
        return toAjax(sysUserParkService.insertByBo(bo));
    }

    /**
     * 修改用户园区关联
     */
    @SaCheckPermission("system:userPark:edit")
    @Log(title = "用户园区关联", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SysUserParkBo bo) {
        return toAjax(sysUserParkService.updateByBo(bo));
    }

    /**
     * 删除用户园区关联
     *
     * @param userParkIds 主键串
     */
    @SaCheckPermission("system:userPark:remove")
    @Log(title = "用户园区关联", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userParkIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] userParkIds) {
        return toAjax(sysUserParkService.deleteWithValidByIds(List.of(userParkIds), true));
    }
}
